﻿<?php
class ZhaopinAction extends BaseAction {

	function index(){//首页

		import('ORG.Util.Page');// 导入分页类
        $areaid = I('get.areaid');


	  if($this->cityid ==370 OR $this->cityid == null){
          $sql = "status=1  AND cid=".$this->cateid;

      }else{
          $sql = "status=1 AND cityid=".$this->cityid." AND cid=".$this->cateid;
      }

        $huojitemp = M('Zhaopin')->where($sql." AND top>=3")->order('createtime DESC')->select();
         foreach ($huojitemp as $v){
             $v['cate'] =M('Category')->where("id=".$v['cid'])->getField("path");

             $shiwanhuoji[]=$v;
         }
         $this->assign("shiwanhuoji",$shiwanhuoji);
	  if(!empty($areaid)){
           $sql = $sql." AND areaid=".$areaid." AND top <3";
           $area = M('Area')->where(array('id'=>$areaid))->getField("name");
            $this->assign("cityname",$area);
        }else{
	      $sql = $sql." AND top <3";
      }



        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $count      = M('Zhaopin')->where($sql)->count();// 查询满足要求的总记录数
        $Page       = new Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数
        $show       = $Page->show();// 分页显示输出
		//城市	
		$temp = M('Zhaopin')->where($sql)->order('top desc,createtime DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

	  foreach ($temp as $v){
			$v['cate'] =M('Category')->where("id=".$v['cid'])->getField("path");
			$list[]=$v;
		}


        $cateid = $_GET['cid'];

        $data = M('Category')->where("path='".$cateid."'")->getField("name");

        $catename = M('Category')->where("id=".$this->cateid)->getField("path");

        $jieshao =  M('Category')->where("path='".$cateid."'")->find();

        $this->diqu = M('area')->where(array('cityid'=>$this->cityid))->select();

        $ad1 = M('Ad')->where("type ='ad1' AND endtime >".mktime())->select();
        $ad2 = M('Ad')->where("type ='ad2' AND endtime >".mktime())->select();

        $this->assign("rightad1",$ad1);
        $this->assign("rightad2",$ad2);
		$this->assign('count',$count);
		$this->assign('infocount',$count);
		$this->assign('list',$list);// 赋值数据集
        $this->assign('jieshao',$jieshao);
		$this->assign('page',$show);// 赋值分页输出
        $this->assign("data",$data); // 分类
        $this->assign('catename',$catename);
		$this->display(); // 输出模板

		
		
		
	}





	function view(){

		$id =empty($_GET['id'])?Exit():$_GET['id'];

			 $info =  M('Zhaopin')->where("status=1 AND id=".$id)->find();
		
			 $company =M('Company')->where("uid=".$info['uid'])->find();
				 
			 $cityName = M('city')->where('id='.$info['cityid'])->find();   /*得到城市*/
			
			 $shengName = M('city')->where('id='.$cityName['cid'])->find();
				
			 $this->user =M('User')->where("uid=".$info['uid'])->find();
		
		     $info['cate']=M('Category')->where("id=".$info['cid'])->find();
				 
			 $temp =  M('Zhaopin')->where("status=1 AND cityid=".$this->cityid)->limit(10)->order("id DESC")->select();
		
			 foreach ($temp as $v){
		
			 	$v['cate'] =M('Category')->where("id=".$v['cid'])->getField("path");
		
			 	$news[]=$v;
		
			 }
		
			 $temp =  M('Zhaopin')->where(array('status'=>1))->limit(10)->order("id DESC")->select();
		
			 foreach ($temp as $v){
		
			 	$v['cate'] =M('Category')->where("id=".$v['cid'])->getField("path");
		
			 	$v['city'] =M('City')->where("id=".$v['cityid'])->getField("pinyin");
		
			 	$list[]=$v;
		
			 }
			 $this->topgg = M('Ad')->where(array('type'=>'详情页顶部','endtime'=>array('gt',time())))->select();
			 $this->assign("cityName",$cityName);
		
			 $this->assign("shengName",$shengName);
			 
			 $this->assign("list",$list);
		
			 $this->assign("news",$news);
		
			 $this->assign("company",$company);
		
			 $this->assign("info",$info);

			
			 $this->display();

	}


}
?>